﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.tendercompanyinfo
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int tcid = (Convert.ToInt32(Request.Params["id"]));
                    lcs.BLL.user bu = new BLL.user();
                    DataSet ds = bu.GetUserRoles(" roles_name='招标公司经理'");
                    ddluser.DataSource = ds.Tables[0];
                    ddluser.DataTextField = "user_name";
                    ddluser.DataValueField = "user_id";
                    ddluser.DataBind();
                    ShowInfo(tcid);
                }
            }
        }

        private void ShowInfo(int tcid)
        {
            lcs.BLL.tendercompanyinfo bll = new lcs.BLL.tendercompanyinfo();
            lcs.Model.tendercompanyinfo model = bll.GetModel(tcid);
            this.lbltcid.Text = model.tcid.ToString();
            this.txttcbh.Text = model.tcbh;
            this.txttcname.Text = model.tcname;
            this.txttcadd.Text = model.tcadd;
            this.txttclink.Text = model.tclink;
            this.txttcphone.Text = model.tcphone;
            this.txttcfax.Text = model.tcfax;
            this.txttcemail.Text = model.tcemail;
            this.ddluser.SelectedValue = model.tcjlid.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txttcbh.Text.Trim().Length == 0)
            {
                strErr += "招标公司编号不能为空！\\n";
            }
            if (this.txttcname.Text.Trim().Length == 0)
            {
                strErr += "名称不能为空！\\n";
            }
            if (this.txttcadd.Text.Trim().Length == 0)
            {
                strErr += "地址不能为空！\\n";
            }
            if (this.txttclink.Text.Trim().Length == 0)
            {
                strErr += "联系人不能为空！\\n";
            }
            
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int tcid = int.Parse(this.lbltcid.Text);
            string tcbh = this.txttcbh.Text;
            string tcname = this.txttcname.Text;
            string tcadd = this.txttcadd.Text;
            string tclink = this.txttclink.Text;
            string tcphone = this.txttcphone.Text;
            string tcfax = this.txttcfax.Text;
            string tcemail = this.txttcemail.Text;
            int tcjlid = int.Parse(this.ddluser.SelectedValue);


            lcs.Model.tendercompanyinfo model = new lcs.Model.tendercompanyinfo();
            model.tcid = tcid;
            model.tcbh = tcbh;
            model.tcname = tcname;
            model.tcadd = tcadd;
            model.tclink = tclink;
            model.tcphone = tcphone;
            model.tcfax = tcfax;
            model.tcemail = tcemail;
            model.tcjlid = tcjlid;

            lcs.BLL.tendercompanyinfo bll = new lcs.BLL.tendercompanyinfo();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "List.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}
